package com.msp.ws.client;

import java.lang.reflect.Type;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;



public class Test {
	private String soapAction = null;
	private String namespace = null;
	private String url = null;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Test test = new Test();
		Type type = new TypeToken<Integer>(){}.getType();
		test.getRotaryFromWSDL("updateDeviceDetailWhenOffline", type);
	}
	
	private String getRotaryFromWSDL(String methodName, Type type) {
		soapAction = "http://impl.ws.msp.com/"+methodName;
		namespace = "http://impl.ws.msp.com/";
		url = "http://192.168.1.103:8080/prctureManager/mspws";
		SoapObject rpc = new SoapObject(namespace, methodName);
//		rpc.addProperty("deviceNo", "000001");
//		rpc.addProperty("deviceName", "小黑2");
		rpc.addProperty("deviceDetailId", 4);
		// 生成调用WebService方法的SOAP请求信息,并指定SOAP的版本
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		// envelope.bodyOut = rpc;
		envelope.setOutputSoapObject(rpc);
		// 设置是否调用的是dotNet开发的WebService
//		envelope.dotNet = true;
//		envelope.setOutputSoapObject(rpc);
		HttpTransportSE transport = new HttpTransportSE(url);
		transport.debug = true;

		try {
			// 调用WebService
			transport.call(soapAction, envelope);

			SoapObject object = (SoapObject) envelope.bodyIn;
			String result = object.getProperty("return")
					.toString();
			new Gson().fromJson(result, type);
			System.out.println("ok");
			return null;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "-4";// if can not connect the webservice
	}

}
